package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.WxSearchVo;
import com.cskaoyan.common.aop.LogAspect;
import com.cskaoyan.service.KeywordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <h1> 小程序端 Footprint Controller</h1>
 * Created by GaoJia
 * Date  2021/10/22 14:39
 */
/**
 * <h1> 小程序端 搜索业务 </h1>
 * Created by GaoJia
 * Date 2021/10/21 15:10
 */
@RestController
@RequestMapping("wx/search")
public class WxSearchController {


    // TODO 测试完成之后去掉
    private final static Logger LOG = LoggerFactory.getLogger(WxSearchController.class);

    @Resource
    KeywordService keywordService;

    @GetMapping("index")
    public BaseRespVo index() {
        /**
         * TODO List  查出所有的搜索记录
         */
        LOG.info("enter");
        WxSearchVo wxSearchVo = keywordService.index();
        LOG.info("return");
        return BaseRespVo.ok();
    }

    /**
     * <h2> 小程序端 关键词检索助手 </h2>
     */
    @GetMapping("helper")
    public BaseRespVo helper(String keyword){
        List keywords = keywordService.helper(keyword);
        return BaseRespVo.ok(keywords);
    }

    /**
     * <h2> 小程序端 清空历史记录 </h2>
     */
    @PostMapping("clearhistory")
    public BaseRespVo clearHistory(@RequestBody Map map){
        // 这个需要用户认证
        keywordService.clearHistory(map);
        return BaseRespVo.ok();
    }
}
